package com.openapi.protocol.decode;

import com.openapi.config.JT808ServerConfig;
import com.openapi.data.JT808PackageData;
import com.openapi.data.JT808PushData;
import com.openapi.protocol.decode.subPackageHandle.mediaFileList.MediaFileList_0x1205;
import com.openapi.server.codec.MsgDecoder;
import exsun.jt808.data.config.jt808.Jt808MsgIdConfig;
import exsun.jt808.data.config.jt808.Jt808MsgIdTopicDic;
import exsun.jt808.data.parseUtil.GpsUtil;
import exsun.jt808.data.upload_data.GpsData;
import exsun.jt808.data.upload_data.Jt808EntityBase;
import exsun.jt808.data.upload_data.jt1078.FileUploadNotice;
import exsun.jt808.data.upload_data.jt808.*;
import exsun.jt808.data.util.parse.DecoderUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * 1078协议解析
 */
@Component
public class Analyze1078 {

	private final static Logger logger = LoggerFactory.getLogger(Analyze1078.class);

	public Analyze1078() {
	}

	@Autowired
	private  MediaFileList_0x1205 mediaFileList_0x1205;


	public JT808PushData mediaFileListDecoder(JT808PackageData packageData){
		return mediaFileList_0x1205.decode(packageData);
	}

	public Jt808EntityBase collectDataDecoder(byte[] body)
	{
		CollectDataResponse data = new CollectDataResponse();
		data.setReqSerialNo(DecoderUtils.parseIntFromBytes(body, 0, 2));
		data.setCmd(DecoderUtils.parseIntFromBytes(body, 2, 1));
		data.setData(DecoderUtils.parseBcdStringFromBytes(body, 3, body.length - 3));
		return data;
	}
	public Jt808EntityBase driverInfoUploadDecoder(byte[] body)
	{
		DriverInfo data = new DriverInfo();
		data.setStatus(DecoderUtils.parseIntFromBytes(body, 0, 1));
		data.setTime(DecoderUtils.parseBcdStringFromBytes(body, 1, 6));
		if (data.getStatus() == 1)
		{
			//System.out.println("heh");
			data.setIcCardreadResult(DecoderUtils.parseIntFromBytes(body, 7, 1));
			if (data.getIcCardreadResult() == 0)
			{
				int n = body[8];
				data.setDriverName(DecoderUtils.parseStringFromBytes(body, 9, n));
				data.setQualificationCode(DecoderUtils.parseStringFromBytes(body, 9 + n, 20));
				int m = body[29 + n];
				data.setIssuingAuthority(DecoderUtils.parseStringFromBytes(body, 30 + n, m));
				data.setCertificateValidity(DecoderUtils.parseBcdStringFromBytes(body, 30 + n + m, 4));
			}
		}
		// 存mongodb（驾驶员、车辆对应关系）
//        driverVehicleStatMongoService.insert(data, clientId);
//        statDriverIdDetailService.save(data, clientId);
		return data;
	}

	public Jt808EntityBase electronicWaybillDecoder(byte[] body)
	{
		ElectronicWaybill data = new ElectronicWaybill();
		int len = DecoderUtils.parseIntFromBytes(body, 0, 4);
		data.setWaybill(DecoderUtils.parseStringFromBytes(body, 4, len));
		// 添加到mongodb
//        vehicleEwayBillMongoService.insertEwayBill(waybill, clientId);
		return data;
	}

	public Jt808EntityBase eventUploadDecoder(byte[] body)
	{
		EventUpload data = new EventUpload();
		data.setEventId(DecoderUtils.parseIntFromBytes(body, 0, 1));
		return data;
	}

	public Jt808EntityBase gpsDecoder(byte[] body)
	{
//        StopWatch stopWatch = new StopWatch();
//        stopWatch.start();
		GpsData data = GpsUtil.parseGps(body,false);

//        stopWatch.stop();
		//logger.info("解析gps消耗时间---" + stopWatch.getTime() / 1000f + "--秒--" + "--设备号--" + data.dvo + "--gps时间--" + data.gdt + "--数据解析时间--" + data.pte);
		return data;
	}

	public Jt808EntityBase mediaEventDecoder(byte[] body)
	{
		MediaEvent data = new MediaEvent();
		data.setMediaId(DecoderUtils.parseIntFromBytes(body, 0, 4));
		data.setMediaType(DecoderUtils.parseIntFromBytes(body, 4, 1));
		data.setCodingType(DecoderUtils.parseIntFromBytes(body, 5, 1));
		data.setEventType(DecoderUtils.parseIntFromBytes(body, 6, 1));
		data.setChannelId(DecoderUtils.parseIntFromBytes(body, 7, 1));
		return data;
	}

	public Jt808EntityBase takePhotoRightAwayDecoder(byte[] body)
	{
		TakePhotoRightAwayResponse data = new TakePhotoRightAwayResponse();
		data.setRepSerialNo(DecoderUtils.parseIntFromBytes(body, 0, 2));
		data.setResult(DecoderUtils.parseIntFromBytes(body, 2, 1));
		int count = DecoderUtils.parseIntFromBytes(body, 3, 2);
		List<Integer> mediaIds = new ArrayList<Integer>();
		int index = 4;
		for (int n = 0; n < count; n++)
		{
			mediaIds.add(DecoderUtils.parseIntFromBytes(body, index, 4));
			index += 4;
		}
		data.setMediaIds(mediaIds);
		return data;
	}

	public Jt808EntityBase terminalAuthenticationDecoder(byte[] body)
	{
		TerminalAuthentication data = new TerminalAuthentication();
		data.setAuthorizeCode(DecoderUtils.parseStringFromBytes(body, 0, body.length));
		return data;
	}

	public Jt808EntityBase terminalCommonResponseDecoder(byte[] body)
	{
		TerminalCommonResponse response = new TerminalCommonResponse();
		response.setOrgSerialNum(DecoderUtils.parseIntFromBytes(body, 0, 2));
		response.setOrgMsgId(DecoderUtils.parseIntFromBytes(body, 2, 2));
		response.setResult(DecoderUtils.parseIntFromBytes(body, 4, 1));
		return response;
	}

	public Jt808EntityBase terminalHearBeatDecoder(byte[] body) {
		// 消息体为空
		return new TerminalHearBeat();
	}

	public Jt808EntityBase terminalLogoutDecoder(byte[] body) {
		// 终端注销消息体为空
		return new TerminalLogout();
	}

	public Jt808EntityBase terminalQueryParamResponseDecoder(byte[] body)
	{
		TerminalParameters data = new TerminalParameters();
		data.setSerialNo(DecoderUtils.parseIntFromBytes(body, 0, 2));
		int parasCount = DecoderUtils.parseIntFromBytes(body, 2, 1);
		int index = 3;
		for (int n = 0; n < parasCount; n++)
		{
			int paraId = DecoderUtils.parseIntFromBytes(body, index, 4);
			index += 4;
			int paraLen = DecoderUtils.parseIntFromBytes(body, index, 1);
			index += 1;
			index += paraLen;
			if(index >= body.length)break;
			switch (paraId)
			{
				case 0x0001:
				{
					data.setHeartbeatInterval(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0002:
				{
					data.setTcpResponseTimeout(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0003:
				{
					data.setTcpRetransmissionCount(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0004:
				{
					data.setUdpResponseTimeout(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0005:
				{
					data.setUdpRetransmissionCount(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0006:
				{
					data.setSmsResponseTimeout(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0007:
				{
					data.setSmsRetransmissionCount(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0010:
				{
					data.setMainServerApn(DecoderUtils.parseStringFromBytes(body, index, paraLen));
					break;
				}
				case 0x0011:
				{
					data.setMainServerUsername(DecoderUtils.parseStringFromBytes(body, index, paraLen));
					break;
				}
				case 0x0012:
				{
					data.setMainServerPassword(DecoderUtils.parseStringFromBytes(body, index, paraLen));
					break;
				}
				case 0x0013:
				{
					data.setMainServerAddress(DecoderUtils.parseStringFromBytes(body, index, paraLen));
					break;
				}
				case 0x0014:
				{
					data.setBackupServerApn(DecoderUtils.parseStringFromBytes(body, index, paraLen));
					break;
				}
				case 0x0015:
				{
					data.setBackupServerUsername(DecoderUtils.parseStringFromBytes(body, index, paraLen));
					break;
				}
				case 0x0016:
				{
					data.setBackupServerPassword(DecoderUtils.parseStringFromBytes(body, index, paraLen));
					break;
				}
				case 0x0017:
				{
					data.setBackupServerAddress(DecoderUtils.parseStringFromBytes(body, index, paraLen));
					break;
				}
				case 0x0018:
				{
					data.setServerTcpPort(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0019:
				{
					data.setServerUdpPort(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x001A:
				{
					data.setRoadTransportIcCardServerAddress(DecoderUtils.parseStringFromBytes(body, index, paraLen));
					break;
				}
				case 0x001B:
				{
					data.setRoadTransportIcCardServerTcpPort(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x001C:
				{
					data.setRoadTransportIcCardServerUdpPort(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x001D:
				{
					data.setRoadTransportIcCardBackupServerAddress(DecoderUtils.parseStringFromBytes(body, index, paraLen));

					break;
				}
				case 0x0020:
				{
					data.setReportingLocationPolicy(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0021:
				{
					data.setReportingLocationProgramme(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0022:
				{
					data.setDriversNotLoggedInDistanceReportingInterval(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0027:
				{
					data.setDormantReportingInterval(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0028:
				{
					data.setEmergencyAlarmReportingInterval(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0029:
				{
					data.setDefaultReportingInterval(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x002C:
				{
					data.setDefaultDistanceReportingInterval(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x002D:
				{
					data.setDriversNotLoggedInDistanceReportingInterval(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x002E:
				{
					data.setDormantDistanceReportingInterval(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x002F:
				{
					data.setEmergencyAlarmDistanceReportingInterval(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0030:
				{
					data.setInflectionPoint(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0031:
				{
					data.setElectronicFenceRadius(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0040:
				{
					data.setMonitoringPlatformPhoneNum(DecoderUtils.parseStringFromBytes(body, index, paraLen));
					break;
				}
				case 0x0041:
				{
					data.setResetPhoneNum(DecoderUtils.parseStringFromBytes(body, index, paraLen));
					break;
				}
				case 0x0042:
				{
					data.setRestoreFactoryPhoneNum(DecoderUtils.parseStringFromBytes(body, index, paraLen));
					break;
				}
				case 0x0043:
				{
					data.setMonitoringPlatformSmsPhoneNum(DecoderUtils.parseStringFromBytes(body, index, paraLen));
					break;
				}
				case 0x0044:
				{
					data.setReceiveDeviceSmsAlarmPhoneNum(DecoderUtils.parseStringFromBytes(body, index, paraLen));
					break;
				}
				case 0x0045:
				{
					data.setTelephoneAnsweringStrategy(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0046:
				{
					data.setEveryTimeTheLongestTalkTime(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0047:
				{
					data.setCurrentMonthTheLongestTalkTime(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0048:
				{
					data.setMonitorPhoneNum(DecoderUtils.parseStringFromBytes(body, index, paraLen));
					break;
				}
				case 0x0049:
				{
					data.setMonitoringPlatformPrivilegesSmsPhoneNum(DecoderUtils.parseStringFromBytes(body, index, paraLen));
					break;
				}
				case 0x0050:
				{
					data.setAlarmScreenCharacter(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0051:
				{
					data.setAlarmSendSmsSwitch(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0052:
				{
					data.setAlarmTakePicSwitch(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0053:
				{
					data.setAlarmTakePicSaveSwitch(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0054:
				{
					data.setKeySwitch(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0055:
				{
					data.setTheHighestSpeed(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0056:
				{
					data.setSpeedingDuration(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0057:
				{
					data.setContinuousDrivingTimeThreshold(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0058:
				{
					data.setCumulativeDrivingTimeThresholdInTheDay(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0059:
				{
					data.setTheMinimumRestTime(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x005A:
				{
					data.setTheMaximumParkingTime(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x005B:
				{
					data.setOverspeedAlarmVaule((float) (DecoderUtils.parseIntFromBytes(body, index, paraLen) / 10.0));
					break;
				}
				case 0x005C:
				{
					data.setTiredDriveringVaule(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x005D:
				{
					int temp = DecoderUtils.parseIntFromBytes(body, index, paraLen);
					data.setCollisionAlarmTime((temp & 0xff) * 4);
					data.setCollisionAcceleration((temp & 0xff00) >> 8);
					break;
				}
				case 0x005E:
				{
					data.setCartwheelAlarmAngle(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0064:
				{
					int temp = DecoderUtils.parseIntFromBytes(body, index, paraLen);
					data.setChannel1TimingTakePhotoFlag(temp & 0x01);
					data.setChannel2TimingTakePhotoFlag((temp & 0x02) >> 1);
					data.setChannel3TimingTakePhotoFlag((temp & 0x04) >> 2);
					data.setChannel4TimingTakePhotoFlag((temp & 0x08) >> 3);
					data.setChannel5TimingTakePhotoFlag((temp & 0x10) >> 4);
					data.setChannel1TimingTakePhotoStorageFlag((temp & 0x0100) >> 8);
					data.setChannel2TimingTakePhotoStorageFlag((temp & 0x0200) >> 9);
					data.setChannel3TimingTakePhotoStorageFlag((temp & 0x0400) >> 10);
					data.setChannel4TimingTakePhotoStorageFlag((temp & 0x0800) >> 11);
					data.setChannel5TimingTakePhotoStorageFlag((temp & 0x1000) >> 12);
					data.setTimingUnit((temp & 0x010000) >> 16);
					data.setTimingInterval((temp & 0xfffe0000) >> 17);
					break;
				}
				case 0x0065:
				{
					int temp = DecoderUtils.parseIntFromBytes(body, index, paraLen);
					data.setChannel1IntervalTakePhotoFlag(temp & 0x01);
					data.setChannel2IntervalTakePhotoFlag((temp & 0x02) >> 1);
					data.setChannel3IntervalTakePhotoFlag((temp & 0x04) >> 2);
					data.setChannel4IntervalTakePhotoFlag((temp & 0x08) >> 3);
					data.setChannel5IntervalTakePhotoFlag((temp & 0x10) >> 4);
					data.setChannel1IntervalTakePhotoStorageFlag((temp & 0x0100) >> 8);
					data.setChannel2IntervalTakePhotoStorageFlag((temp & 0x0200) >> 9);
					data.setChannel3IntervalTakePhotoStorageFlag((temp & 0x0400) >> 10);
					data.setChannel4IntervalTakePhotoStorageFlag((temp & 0x0800) >> 11);
					data.setChannel5IntervalTakePhotoStorageFlag((temp & 0x1000) >> 12);
					data.setIntervalUnit((temp & 0x010000) >> 16);
					data.setSpacingInterval((temp & 0xfffe0000) >> 17);
					break;
				}
				case 0x0070:
				{
					data.setImageVideoQuality(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0071:
				{
					data.setBrightness(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0072:
				{
					data.setContrast(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0073:
				{
					data.setSaturation(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0074:
				{
					data.setChroma(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0080:
				{
					data.setVehicleOdometerReadings((float) (DecoderUtils.parseIntFromBytes(body, index, paraLen) / 10.0));
					break;
				}
				case 0x0081:
				{
					data.setProvincialId(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0082:
				{
					data.setCityId(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0083:
				{
					data.setTheLicensePlateNumber(DecoderUtils.parseStringFromBytes(body, index, paraLen));
					break;
				}
				case 0x0084:
				{
					data.setLicensePlateColor(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0090:
				{
					int temp = DecoderUtils.parseIntFromBytes(body, index, paraLen);
					data.setGpsPositioningFlag(temp & 0x01);
					data.setBdPositioningFlag((temp & 0x02) >> 1);
					data.setGlonassPositioningFlag((temp & 0x04) >> 2);
					data.setGalileoPositioningFlag((temp & 0x08) >> 3);
					break;
				}
				case 0x0091:
				{
					data.setGnssBaudRate(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0092:
				{
					data.setGnssLocationingOutputFrequency(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0093:
				{
					data.setGnssLocationingCollectFrequency(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0094:
				{
					data.setGnssLocationingUploadType(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0095:
				{
					data.setGnssLocationingUploadUnit(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0100:
				{
					data.setCan1CollectTimeInterval(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0101:
				{
					data.setCan1UploadTimeInterval(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0102:
				{
					data.setCan2CollectTimeInterval(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0103:
				{
					data.setCan2UploadTimeInterval(DecoderUtils.parseIntFromBytes(body, index, paraLen));
					break;
				}
				case 0x0110:
				{
					int tempH = DecoderUtils.parseIntFromBytes(body, index, paraLen / 2);
					int tempL = DecoderUtils.parseIntFromBytes(body, index + 4, paraLen / 2);
					data.setCollectTimeInterval(tempH & 0xffffffff);
					data.setCanChannelId((tempL & 0x80000000) >> 31);
					data.setFramesType((tempL & 0x40000000) >> 30);
					data.setDataCollectType((tempL & 0x20000000) >> 29);
					data.setCanId(tempL & 0x1fffffff);
					break;
				}
				default:
					break;
			}
		}
		return data;
	}

	public Jt808EntityBase terminalQueryPropResponseDecoder(byte[] body)
	{
		TerminalProperty data = new TerminalProperty();
		int type = DecoderUtils.parseIntFromBytes(body, 0, 2);
		data.setApplyPassengerVehicle(type & 0x01);
		data.setApplyDangerousVehicle((type & 0x02) >> 1);
		data.setApplyGeneralCargoVehicle((type & 0x04) >> 2);
		data.setApplyRentedOutVehicle((type & 0x08) >> 3);
		data.setHardDiskRecord((type & 0x40) >> 6);
		data.setModel((type & 0x80) >> 7);
		data.setTerminalManufacturerCode(DecoderUtils.parseStringFromBytes(body, 2, 5));
		data.setTerminalModel(DecoderUtils.parseStringFromBytes(body, 7, 20));
		data.setTerminalId(DecoderUtils.parseStringFromBytes(body, 27, 7));
		data.setICCID(DecoderUtils.parseBcdStringFromBytes(body, 34, 10));
		int n = body[44];
		data.setTerminalHardwareVersion(DecoderUtils.parseBcdStringFromBytes(body, 45, n));
		int m = body[45 + n];
		data.setTerminalFirmwareVersion(DecoderUtils.parseBcdStringFromBytes(body, 46 + n, m));
		int gnssProp = body[46 + n + m];
		data.setGpsLocationing(gnssProp & 0x01);
		data.setBdLocationing((gnssProp & 0x02) >> 1);
		data.setGlonassLocationing((gnssProp & 0x04) >> 2);
		data.setGalileoLocationing((gnssProp & 0x08) >> 3);
		int communicationProp = DecoderUtils.parseIntFromBytes(body, 47 + n + m, 1);
		data.setGprs(communicationProp & 0x01);
		data.setCdma((communicationProp & 0x02) >> 1);
		data.setTdScdma((communicationProp & 0x04) >> 2);
		data.setWcdma((communicationProp & 0x08) >> 3);
		data.setCdma2000((communicationProp & 0x10) >> 4);
		data.setTdLte((communicationProp & 0x20) >> 5);
		data.setOtherComunication((communicationProp & 0x80) >> 7);
		return data;
	}

	Jt808EntityBase terminalRegisterDecoder(byte[] body)
	{
		TerminalRegister data = new TerminalRegister();
		data.setProvincialId(DecoderUtils.parseIntFromBytes(body, 0, 2));
		data.setCityId(DecoderUtils.parseIntFromBytes(body, 2, 2));
		data.setManufacturerId(DecoderUtils.parseStringFromBytes(body, 4, 5));
		data.setTerminalType(DecoderUtils.parseStringFromBytes(body, 9, 20));
		data.setTerminalId(DecoderUtils.parseStringFromBytes(body, 29, 7));
		data.setLicensePlateColor(DecoderUtils.parseIntFromBytes(body, 36, 1));
		data.setVehicleLicensePlate(DecoderUtils.parseStringFromBytes(body, 37, body.length - 37));
		return data;
	}

	public Jt808EntityBase upgradeResponseDecoder(byte[] body)
	{
		UpgradeResponse data = new UpgradeResponse();
		data.setType(DecoderUtils.parseIntFromBytes(body, 0, 1));
		data.setResult(DecoderUtils.parseIntFromBytes(body, 1, 1));
		return data;
	}

	public Jt808EntityBase vehicleControlResponseDecoder(byte[] body) {
//        String strPosition = msgBody.substring(4, msgBody.length());
//        PositionInfo data = jt808ParseUtil.getPositionInfo(clientId, "true", strPosition);
		TerminalLogout data = new TerminalLogout();
		return data;
	}

	/**
	 * 文件上传完成应答
	 */
	public static Jt808EntityBase fileUploadResponse(JT808PackageData packageData){
		byte[] body = packageData.getBodyBuffers();
		FileUploadNotice data = new FileUploadNotice();
		data.setResponSerialNum(DecoderUtils.parseIntFromBytes(body,0,2));
		data.setUploadResult(DecoderUtils.parseIntFromBytes(body,2,1));
		return data;
	}
}
